<template>
  <el-input v-model="keyMessage" style="width: 20%"></el-input>
  <el-button @click="searchMessage" type="primary">信息检索</el-button><br>
<!--  <el-table :data="tableDateForSearch" style="width: 100%" >
    <el-table-column prop="messageId" label="Id" width="180" />
    <el-table-column prop="senderAdmin" label="发送者账号" width="180" />
    <el-table-column prop="senderName" label="发送者姓名" width="180" />
    <el-table-column prop="receiverAdmin" label="接收者账户" width="180" />
    <el-table-column prop="message" label="消息"  width="180"/>
    <el-table-column prop="isRead" label="是否已读" width="180" />
    <el-table-column align="right">
      <template #default="scope">
        <el-button size="small" @click="sendRequest(scope.$index, scope.row)"
        >添加好友</el-button
        >
        <el-button
            type="danger"
            size="small"
            @click.prevent="deleteRow(scope.$index)"
        >
          删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>-->
  <el-table :data="tableDataForAll" style="width: 100%" >
    <el-table-column prop="messageId" label="Id" width="180" />
    <el-table-column prop="senderAdmin" label="发送者账号" width="180" />
    <el-table-column prop="senderName" label="发送者姓名" width="180" />
    <el-table-column prop="receiverAdmin" label="接收者账户" width="180" />
    <el-table-column prop="message" label="消息"  width="180" style="color: #a6c1ee"/>
    <el-table-column prop="isRead" label="是否已读" width="180" />
    <el-table-column align="right">
      <template #default="scope">
        <el-button size="small"
                   type="warning"
                   @click="sendRequest(scope.$index, scope.row)"
        >警告</el-button
        >
        <el-button
            type="danger"
            size="small"
            @click="suspend(scope.$index)"
        >
          封号
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  name: "MessageManageView",
  data(){
    return{
      tableDataForAll:'',
      tableDateForSearch:'',
      keyMessage:'',
      button_title:'警告'
    }
  },
  created() {
    const _this=this
    axios({
      method: 'post',
      url: 'http://localhost:8081/showAllMessage',
      params: {}
    })
        .then(function (response) {

          console.log(response)
          _this.tableDataForAll = response.data

        })
        .catch(function (error) {
          console.log(error);
        });
  },
  methods:{
    searchMessage(){
      const _this=this
      axios({
        method: 'post',
        url: 'http://localhost:8081/flexibleQueryMessage',
        params: {
          message:this.keyMessage
        }
      })
          .then(function (response) {

            console.log(response)
            _this.tableDataForAll = response.data

          })
          .catch(function (error) {
            console.log(error);
          });
    },
    suspend(index){
    /*  if(this.button_title=="封号"){
        this.button_title="解封";
      }else {
        this.button_title="";
      }*/
    const isSuspend =confirm("将对发送者账号封禁，请谨慎操作")
    if(isSuspend){
      ElMessage({
        message:"封号成功",
        type:"success"
      })
      axios({
        method: 'post',
        url: 'http://localhost:8081/suspendUser',
        params: {
          userName:this.tableDataForAll.at(index).senderAdmin
        }
      })
          .then(function (response) {

            console.log(response)

          })
          .catch(function (error) {
            console.log(error);
          });
    }
    }
    }

}
</script>

<style scoped>

</style>